package com.yztc.yidoutang.activity.darenshow_activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.yztc.yidoutang.R;
import com.yztc.yidoutang.adapter.DaRenShowAdapter;
import com.yztc.yidoutang.base.BaseActivity;
import com.yztc.yidoutang.bean.DaRenShowListBean;

import java.util.List;

/**
 * Created by My on 2016/10/19.
 */

public class DaRenShowActivity extends BaseActivity implements DaRenShowContract.View {
    private LinearLayout ll;
    private SwipeRefreshLayout swipeLayout;
    private int page=1;
    private TextView tv_title;
    private DaRenShowPresenter presenter=new DaRenShowPresenter(this);
    private ListView lv;
    private DaRenShowAdapter adapter;
    private String type;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        refresh();
    }



    private void refresh() {
        swipeLayout.setColorSchemeResources(R.color.clr_orange);
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        presenter.getDataForNet(1+"",type+"");
                        swipeLayout.setRefreshing(false);
                    }
                },2000);
            }
        });
    }

    private void initView() {
        ll= (LinearLayout) findViewById(R.id.drs_ll);
        swipeLayout= (SwipeRefreshLayout) findViewById(R.id.drs_swipe_layout);
        lv= (ListView) findViewById(R.id.drs_lv);
        tv_title= (TextView) findViewById(R.id.drs_tv);
        Intent intent=getIntent();
        type=intent.getStringExtra("type");
        presenter.getDataForNet(page+"",type);
    }

    @Override
    public void onDaRenSuccess(List<DaRenShowListBean> list) {
        if (adapter==null){
            tv_title.setText(list.get(1).getTagname());
            adapter=new DaRenShowAdapter(DaRenShowActivity.this,list);
            lv.setAdapter(adapter);
        }else {
            adapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onDaRenFail(String msg) {

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_darenshow;
    }
    public void DRSClick(View view){
        switch (view.getId()){
            case R.id.drs_btn_back:
                finish();
                break;
        }
    }

}
